package com.youmingxing.adpter.selfInfo;


import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.youmingxing.R;
import com.youmingxing.activity.selfInfo.PersonalInfoActivity;
import com.youmingxing.bean.selfinfo.AuditionRank;
import com.youmingxing.utils.ViewHolderUtils;

import java.util.List;

import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * 我的海选
 */
public class AuditionTopRankAdapter extends BaseAdapter {
    private List<AuditionRank> auditionRankList;
    private TextView nameTv;
    private TextView rankingnumTv;
    private TextView ticketnumTv;
    private ImageView icon;

    private Context context;


    public AuditionTopRankAdapter(Context mContext, List<AuditionRank> auditionRankList) {
        this.context = mContext;
        this.auditionRankList = auditionRankList;
    }

    @Override
    public int getCount() {
        return auditionRankList == null ? 0 : auditionRankList.size();
    }

    @Override
    public Object getItem(int position) {
        if ((null != auditionRankList && auditionRankList.size() > 0) && (position >= 0 && position < auditionRankList.size())) {
            return auditionRankList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_audition_top4, null);
        }
        nameTv = ViewHolderUtils.getViewHolderView(convertView, R.id.actor_name);
        rankingnumTv = ViewHolderUtils.getViewHolderView(convertView, R.id.top_rank);
        ticketnumTv = ViewHolderUtils.getViewHolderView(convertView, R.id.vote_number);

        icon = ViewHolderUtils.getViewHolderView(convertView, R.id.actor_image);

        nameTv.setText(auditionRankList.get(position).nickname);
        ticketnumTv.setText(auditionRankList.get(position).votes + "票");
        Glide.with(context).load(auditionRankList.get(position).headimg)
                .placeholder(R.drawable.default_avatar).error(R.drawable.default_avatar)
                .bitmapTransform(new CropCircleTransformation(context)).crossFade().into(icon);
        if (auditionRankList.get(position).status == 2) {
            rankingnumTv.setText("已入围");
            rankingnumTv.setTextColor(Color.parseColor("#EA4141"));
            rankingnumTv.setBackgroundResource(R.drawable.roundconner_rededge);
        } else {
            int rank = position + 1;
            rankingnumTv.setText("TOP" + rank);
            rankingnumTv.setBackgroundResource(R.drawable.roundconner_yellow);
            rankingnumTv.setTextColor(Color.parseColor("#fdfdfd"));
        }

        icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PersonalInfoActivity.class);
                intent.putExtra("u_id", auditionRankList.get(position).u_id);
                context.startActivity(intent);
            }
        });


        return convertView;
    }

}